/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controlador;

import Facade.VoluntarioFacade;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author Alan
 */
public class MantenedorVoluntariosAction extends DispatchAction {
    
    /* forward name="success" path="" */
    private final static String MODIFICAR = "modificar";
    private final static String MODIFICARFAILURE = "modificarfailure";
    private final static String INGRESAR = "ingresar";
    private final static String ELIMINAR = "eliminar";
    private final static String CONSULTAR = "consultar";
    private final static String CONSULTARFAILURE = "consultarfailure";
    private final static String HOME ="inicio";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward modificarVoluntarios(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {


        VoluntarioFacade fcdVoluntario = new VoluntarioFacade();

        Vector resultado = fcdVoluntario.cargarVoluntarios();
        
        request.setAttribute("listaVoluntarios", resultado);

        if(resultado != null) return mapping.findForward(MODIFICAR);
        else return mapping.findForward(MODIFICARFAILURE);
    }

    public ActionForward ingresarVoluntario(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        return mapping.findForward(INGRESAR);
    }

     public ActionForward eliminarVoluntario(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        return mapping.findForward(ELIMINAR);
    }

      public ActionForward cargarVoluntariosVigentes(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {


        VoluntarioFacade fcdVoluntario = new VoluntarioFacade();

        Vector resultado = fcdVoluntario.cargarVoluntariosVigentes();

        request.setAttribute("listaVoluntariosVigentes", resultado);
      
        if(resultado != null) return mapping.findForward(CONSULTAR);
        else return mapping.findForward(CONSULTARFAILURE);
    }

      public ActionForward inicio(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        return mapping.findForward(HOME);
    }
}
